<template>
	<view>
		<uni-search-bar @input="input"></uni-search-bar>
		<view class="suggest-list">
			<view class="suggest-item" v-for="item in searchList" :key="item.goods_id" @click="goToGoods(item.goods_id)">
				<text>{{item.goods_name}}</text>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				kw: '',
				timer: null,
				searchList : []
			};
		},
		methods: {
			goToGoods(id) {
				uni.navigateTo({
					url:`/subpkg/goods_detail/goods_detail?goods_id=${id}`
				})
			},
			input(e) {
				clearTimeout(this.timer)
				this.timer = setTimeout(async () => {
					let {data} = await uni.$http.get('/api/public/v1/goods/qsearch',{
						query : e
					})
					if(data.meta.status !== 200) return uni.$showMsg
					this.searchList = data.message
				}, 500)
			}
		}
	}
</script>

<style lang="scss">
.suggest-item{
	padding: 5px;
}
</style>